package com.example.sjly.ui.mymaterial;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.Navigation;

import com.example.sjly.MainActivity;
import com.example.sjly.R;
import com.example.sjly.db.LoginUser;
import com.example.sjly.sqliteroom.AppRoomDatabase;
import com.example.sjly.sqliteroom.User;
import com.example.sjly.sqliteroom.UserDao;
import com.example.sjly.ui.login_register.PersonInfo;
import com.example.sjly.ui.login_register.login;
import com.example.sjly.utils.PhotoUtils;

import java.util.Objects;

import static android.app.Activity.RESULT_OK;

public class MymaterialFragment extends Fragment {
    private Button Mymessage;
    private Button Login;
    private Button shezhi;//设置
    private Button kefu;//客服
    private Button kecheng;//课程
    private Button xinxi;//信息
    private Button exit;
    private String username;
    private TextView textView1;
    private TextView textView2;
    private ImageView imageView;
    private PhotoUtils photoUtils=new PhotoUtils();
    User user;



    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_mymaterial, container, false);
        LoginUser loginUser=LoginUser.getInstance();
        textView1=root.findViewById(R.id.textView);
        textView2=root.findViewById(R.id.textView2);
        imageView=root.findViewById(R.id.imageView);
        textView1.setText("  昵称:"  +loginUser.getName());
        textView2.setText("  ID号:"  +String.valueOf(loginUser.getId()));
        imageView.setImageResource(R.drawable.pig);

        Mymessage = root.findViewById(R.id.button2);
        Mymessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                    Intent intent = new Intent(getActivity(), PersonInfo.class);
                    startActivity(intent);
            }
        });

        Login = root.findViewById(R.id.button1);
        Login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                    Intent intent = new Intent(getActivity(), PersonInfo.class);
                    startActivity(intent);

            }
        });

        kecheng=root.findViewById(R.id.button3);
        kecheng.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(),"网络开小差了...",Toast.LENGTH_SHORT).show();
            }
        });
        xinxi=root.findViewById(R.id.button4);
        xinxi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(),"网络开小差了...",Toast.LENGTH_SHORT).show();
            }
        });
        kefu=root.findViewById(R.id.button5);
        kefu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(),"网络开小差了...",Toast.LENGTH_SHORT).show();
            }
        });
        shezhi=root.findViewById(R.id.button6);
        shezhi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(),"暂无可设置内容...",Toast.LENGTH_SHORT).show();
            }
        });
        exit=root.findViewById(R.id.button7);
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().finish();
            }
        });
        return root;
    }

    @Override
    public void onResume(){
        super.onResume();
        refreshData();
    }

    private void refreshData() {
        try {
                    LoginUser loginUser=LoginUser.getInstance();
                    textView1.setText("  昵称:"+loginUser.getName());
        }catch (NullPointerException e){
            e.printStackTrace();
        }
    }

}